<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" 
	xmlns:of="http://omnifaces.org/functions"
	template="/WEB-INF/templates/template.xhtml">
	
<ui:define name="headIncludes">
	<f:event listener="#{compraBean.initialize}" type="preRenderView"/>
</ui:define>
	
	<ui:define name="pageName">Consultar Compra</ui:define>
	
	<ui:define name="buttons">
		<p:commandButton value="Nova" style="height:28px;" action="#{compraBean.changeToNew}" icon="ui-icon-plus"/>
	</ui:define>
	
	<ui:define name="content">	
		<p:panel>
			<div>
				<p:messages autoUpdate="true"/>
				<h:panelGrid columns="10">
					<h:outputText value="Filtrar por:" />
									
					<p:inputText id="inputSearchFilterNum" style="width:100px;" value="#{compraBean.filterNum}" maxlength="20" title="Número da nota"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButtonCompra').click(); }"/>
					<p:watermark value="Número da nota" for="inputSearchFilterNum"/>
					
					<p:inputText id="inputSearchFilterSerie" style="width:100px;" value="#{compraBean.filterSerie}" maxlength="20" title="Número de série"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButtonCompra').click(); }"/>
					<p:watermark value="Número de série" for="inputSearchFilterSerie"/>
				
					<p:inputText id="inputSearchFilterForn" style="width:250px;" value="#{compraBean.filterFornecedor}" maxlength="100" title="Fornecedor"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButtonCompra').click(); }"/>
					<p:watermark value="Fornecedor" for="inputSearchFilterForn"/>
					
					<p:calendar id="inputSearchFilterData" value="#{compraBean.filterDataEmissao}" navigator="true"
						readonlyInput="true" showButtonPanel="true" locale="pt_BR" pattern="dd/MM/yyyy" title="Data de emissão"
						onkeypress="if (event.keyCode == 13) { event.preventDefault();  $('#searchButtonCompra').click(); }"/>
					<p:watermark value="Data de emissão" for="inputSearchFilterData"/>
					
					<p:commandButton value="Consultar" style="height:28px;" id="searchButtonCompra" update="@form" actionListener="#{compraBean.fillByFilter}" icon="ui-icon-search"/>				
				</h:panelGrid>
	
				<div style="padding-top:10px;">
					<p:dataTable var="compra" id="tableCompra" 
						value="#{compraBean.compras}"
						paginator="true" rows="10" paginatorPosition="bottom"
						emptyMessage="Não há registros">  
						
				        <p:column headerText="Número da nota" width="100" style="text-align:center;">  
				            <h:outputText value="#{of:abbreviate(compra.notaPK.numeroNota, 15)}" />  
				        </p:column>  
				  
				        <p:column headerText="Número de série" width="100" style="text-align:center;">  
				            <h:outputText value="#{of:abbreviate(compra.notaPK.numeroSerie, 15)}" />  
				        </p:column> 
				        
				        <p:column headerText="Fornecedor">  
				            <h:outputText value="#{of:abbreviate(compra.fornecedor.nome, 80)}" />  
				        </p:column>   
				        
				        <p:column headerText="Valor" width="120" style="text-align:center;">  
				            <h:outputText value="#{compra.totalNota}">
				    			<f:convertNumber pattern="R$ #,###,##0.00" />
				    		</h:outputText> 
				        </p:column> 
				        <p:column headerText="Data de emissão" width="100" style="text-align:center;">  
				            <h:outputText value="#{compra.emissao}">
				    			<f:convertDateTime pattern="dd/MM/yyyy"/>
				    		</h:outputText> 
				        </p:column> 
	        
				        <p:column headerText="" width="10">
							<p:commandButton icon="ui-icon-search"
								style="width: 24px; height: 24px;" action="#{compraBean.changeToDetail(compra.notaPK.numeroNota, compra.notaPK.numeroSerie, compra.fornecedor.id)}" title="Visualizar"/>
						</p:column> 
		
			  	  </p:dataTable>
				</div>
			</div>
		</p:panel>
						 
	</ui:define>

</ui:composition>